package main.java.easy;

import main.java.structure.TreeNode;
/**
 * @Author: 郑国荣
 * @Date: 2023-07-30-14:48
 * @Description: 相同的树
 */
public class SameTree {
    public static boolean isSameTree(TreeNode p,TreeNode q){
        if (p==null&&q==null) return true;
        if (p==null||q==null) return false;
        if (p.val != q.val) return false;
        return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
    }

    public static void main(String[] args) {
        TreeNode p = new TreeNode(1,new TreeNode(2,new TreeNode(4),new TreeNode(5)),new TreeNode(1));
        TreeNode q = new TreeNode(1,new TreeNode(2,new TreeNode(4),new TreeNode(5)),new TreeNode(1));
        System.out.println(isSameTree(p, q));
    }


}
